package com.homepage.service;

import com.homepage.domain.CompanyLogo;
import com.homepage.repository.CompanyLogoRepository;
import com.homepage.service.dto.CompanyLogoDTO;
import com.homepage.service.mapper.CompanyLogoMapper;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service Implementation for managing {@link CompanyLogo}.
 */
@Service
@Transactional
public class CompanyLogoService {

    private final Logger log = LoggerFactory.getLogger(CompanyLogoService.class);

    private final CompanyLogoRepository companyLogoRepository;

    private final CompanyLogoMapper companyLogoMapper;

    public CompanyLogoService(CompanyLogoRepository companyLogoRepository, CompanyLogoMapper companyLogoMapper) {
        this.companyLogoRepository = companyLogoRepository;
        this.companyLogoMapper = companyLogoMapper;
    }

    public CompanyLogoDTO findByCompanyName(String companyName)
    {
        return companyLogoRepository.findCompanyLogoByCompanyId(companyName).map(companyLogoMapper::toDto).get();
    }
    /**
     * Save a companyLogo.
     *
     * @param companyLogoDTO the entity to save.
     * @return the persisted entity.
     */
    public CompanyLogoDTO save(CompanyLogoDTO companyLogoDTO) {
        log.debug("Request to save CompanyLogo : {}", companyLogoDTO);
        CompanyLogo companyLogo = companyLogoMapper.toEntity(companyLogoDTO);
        companyLogo = companyLogoRepository.save(companyLogo);
        return companyLogoMapper.toDto(companyLogo);
    }

    /**
     * Partially update a companyLogo.
     *
     * @param companyLogoDTO the entity to update partially.
     * @return the persisted entity.
     */
    public Optional<CompanyLogoDTO> partialUpdate(CompanyLogoDTO companyLogoDTO) {
        log.debug("Request to partially update CompanyLogo : {}", companyLogoDTO);

        return companyLogoRepository
            .findById(companyLogoDTO.getId())
            .map(existingCompanyLogo -> {
                companyLogoMapper.partialUpdate(existingCompanyLogo, companyLogoDTO);

                return existingCompanyLogo;
            })
            .map(companyLogoRepository::save)
            .map(companyLogoMapper::toDto);
    }

    /**
     * Get all the companyLogos.
     *
     * @return the list of entities.
     */
    @Transactional(readOnly = true)
    public List<CompanyLogoDTO> findAll() {
        log.debug("Request to get all CompanyLogos");
        return companyLogoRepository.findAll().stream().map(companyLogoMapper::toDto).collect(Collectors.toCollection(LinkedList::new));
    }

    /**
     * Get one companyLogo by id.
     *
     * @param id the id of the entity.
     * @return the entity.
     */
    @Transactional(readOnly = true)
    public Optional<CompanyLogoDTO> findOne(Long id) {
        log.debug("Request to get CompanyLogo : {}", id);
        return companyLogoRepository.findById(id).map(companyLogoMapper::toDto);
    }

    /**
     * Delete the companyLogo by id.
     *
     * @param id the id of the entity.
     */
    public void delete(Long id) {
        log.debug("Request to delete CompanyLogo : {}", id);
        companyLogoRepository.deleteById(id);
    }
}
